using System;
using System.Collections.Generic;
using UnionAssets.FLE;
using UnityEngine;

public class iAdBannerController : EventDispatcher
{
	private static int _nextId;

	private static iAdBannerController _instance;

	private Dictionary<int, iAdBanner> _banners;

	public Action InterstitialDidFailWithErrorAction = delegate
	{
	};

	public Action InterstitialAdWillLoadAction = delegate
	{
	};

	public Action InterstitialAdDidLoadAction = delegate
	{
	};

	public Action InterstitialAdDidFinishAction = delegate
	{
	};

	public static iAdBannerController instance
	{
		get
		{
			if (_instance == null)
			{
				_instance = UnityEngine.Object.FindObjectOfType(typeof(iAdBannerController)) as iAdBannerController;
				if (_instance == null)
				{
					_instance = new GameObject("iAdBannerController").AddComponent<iAdBannerController>();
				}
			}
			return _instance;
		}
	}

	public static int nextId
	{
		get
		{
			_nextId++;
			return _nextId;
		}
	}

	public List<iAdBanner> banners
	{
		get
		{
			List<iAdBanner> list = new List<iAdBanner>();
			if (_banners == null)
			{
				return list;
			}
			foreach (KeyValuePair<int, iAdBanner> banner in _banners)
			{
				list.Add(banner.Value);
			}
			return list;
		}
	}

	private void Awake()
	{
		_banners = new Dictionary<int, iAdBanner>();
		UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
	}

	public iAdBanner CreateAdBanner(TextAnchor anchor)
	{
		iAdBanner iAdBanner2 = new iAdBanner(anchor, nextId);
		_banners.Add(iAdBanner2.id, iAdBanner2);
		return iAdBanner2;
	}

	public iAdBanner CreateAdBanner(int x, int y)
	{
		iAdBanner iAdBanner2 = new iAdBanner(x, y, nextId);
		_banners.Add(iAdBanner2.id, iAdBanner2);
		return iAdBanner2;
	}

	public void DestroyBanner(int id)
	{
		if (_banners != null && _banners.ContainsKey(id))
		{
			_banners.Remove(id);
		}
	}

	public void StartInterstitialAd()
	{
	}

	public void LoadInterstitialAd()
	{
	}

	public void ShowInterstitialAd()
	{
	}

	public iAdBanner GetBanner(int id)
	{
		if (_banners.ContainsKey(id))
		{
			return _banners[id];
		}
		if (!IOSNativeSettings.Instance.DisablePluginLogs)
		{
			BCWDebug.LogWarning("Banner id: " + id + " not found");
		}
		return null;
	}

	private void didFailToReceiveAdWithError(string bannerID)
	{
		int id = Convert.ToInt32(bannerID);
		iAdBanner banner = GetBanner(id);
		if (banner != null)
		{
			banner.didFailToReceiveAdWithError();
		}
	}

	private void bannerViewDidLoadAd(string bannerID)
	{
		int id = Convert.ToInt32(bannerID);
		iAdBanner banner = GetBanner(id);
		if (banner != null)
		{
			banner.bannerViewDidLoadAd();
		}
	}

	private void bannerViewWillLoadAd(string bannerID)
	{
		int id = Convert.ToInt32(bannerID);
		iAdBanner banner = GetBanner(id);
		if (banner != null)
		{
			banner.bannerViewWillLoadAd();
		}
	}

	private void bannerViewActionDidFinish(string bannerID)
	{
		int id = Convert.ToInt32(bannerID);
		iAdBanner banner = GetBanner(id);
		if (banner != null)
		{
			banner.bannerViewActionDidFinish();
		}
	}

	private void bannerViewActionShouldBegin(string bannerID)
	{
		int id = Convert.ToInt32(bannerID);
		iAdBanner banner = GetBanner(id);
		if (banner != null)
		{
			banner.bannerViewActionShouldBegin();
		}
	}

	private void interstitialdidFailWithError(string data)
	{
		dispatch("interstitial_did_fail_with_error");
		InterstitialDidFailWithErrorAction();
	}

	private void interstitialAdWillLoad(string data)
	{
		dispatch("interstitial_ad_will_load");
		InterstitialAdWillLoadAction();
	}

	private void interstitialAdDidLoad(string data)
	{
		dispatch("interstitial_ad_did_load");
		InterstitialAdDidLoadAction();
	}

	private void interstitialAdActionDidFinish(string data)
	{
		dispatch("interstitial_ad_action_did_finish");
		InterstitialAdDidFinishAction();
	}
}
